#!/bin/bash

# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2009-2016 Lukas Rusak (lrusak@libreelec.tv)

if [ -z "$PROJECT" -a -z "$ARCH" ]; then
  echo "Usage: PROJECT=<project> ARCH=<arch> $0"
  exit 0
fi

help() {
  echo "Usage: PROJECT=<project> ARCH=<arch> $0 [-a|--all]"
  echo "Options:"
  echo "  -a, --all: download all packages including addons"
}

case $1 in
  -a|--all)
  ALL_PACKAGES="true"
  ;;
  -h|--help)
  help
  exit 0
esac

for package in $(find packages/ -name package.mk); do
  if [ -n "$(echo $package | grep addons)" -a -z "$ALL_PACKAGES" ]; then
    continue
  fi
  ./scripts/get $(basename `dirname $package`)
done
